package cn.wolfcode.wolf2w.controller;


import cn.wolfcode.wolf2w.domain.UserInfo;
import cn.wolfcode.wolf2w.domain.Visitor;
import cn.wolfcode.wolf2w.redis.service.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.redis.service.IUserInfoRedisService;
import cn.wolfcode.wolf2w.service.IUserInfoService;
import cn.wolfcode.wolf2w.service.IUserfavorService;
import cn.wolfcode.wolf2w.service.IVisitorService;
import cn.wolfcode.wolf2w.util.JsonResult;
import cn.wolfcode.wolf2w.util.UserParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("users")
public class VisitorController {
    @Autowired
    private IVisitorService visitorService;
    @Autowired
    private IUserInfoService userInfoService;
    @Autowired
    private IStrategyStatisVORedisService redisService;

    @GetMapping("/get1")
    public Object query(@UserParam UserInfo userInfo, String ownerId) {
        List<UserInfo> list=new ArrayList<>();
        Visitor visitor = null;
        if (!userInfo.getId().equals(ownerId)) {
            visitor = visitorService.getByOwnerId(ownerId, userInfo.getId());
        }else {
            visitor = visitorService.queryByOwnerId(ownerId, userInfo.getId());
        }
        List<String> uids = visitor.getVistors();
        for (String uid : uids) {
            list.add( userInfoService.get(uid));
        }

        return JsonResult.success(list);

    }
    @GetMapping("/get2")
    public Object query2(@UserParam UserInfo userInfo, String ownerId) {

        Visitor visitor = null;
        if (!userInfo.getId().equals(ownerId)) {
            visitor = visitorService.getByOwnerId(ownerId,userInfo.getId());
        }else {
            visitor = visitorService.queryByOwnerId(ownerId, userInfo.getId());
        }
        return JsonResult.success(visitor.getTotalCount());

    }
    @GetMapping("/get3")
    public Object query3(@UserParam UserInfo userInfo, String ownerId) {
        Object todayView =null;
        if (!userInfo.getId().equals(ownerId)) {
            todayView = redisService.getTodayView(ownerId);
        }else {
            todayView = redisService.getTodayView1(ownerId);
        }

        return JsonResult.success(todayView);

    }

}
